import { Plugin } from "vite"
import { defineConfig } from "vite";
import path from "path";

import vue from "@vitejs/plugin-vue";
import inspect from "vite-plugin-inspect";
import devtools from "vite-plugin-vue-devtools";

const htmlScriptInsertPlugin = () => {
  return <Plugin>{
    name: "html-script-insert",
    transformIndexHtml: {
      order: "post",
      handler: (html) => {
        const script = /* js */`
          document.scrollingElement?.classList.add("scrollingElement")
        `;
        return html.replace("</body>", `<script>${script}</script></body>`);
      },
    },
  }
}
export default defineConfig({
  resolve: {
    alias: {
      "@": path.resolve(process.cwd(), "src"),
    },
  },
  plugins: [vue(), devtools(), inspect(), htmlScriptInsertPlugin()],
  css: {
    preprocessorOptions: {
      less: <Less.Options>{
        math: "parens-division", // 4.0 default
        globalVars: {
        }
      },
    },
  },
  server: {
    port: 9910,
  },
});
